var WarnFormModel = function (warn) {
  BaseModel.call(this);
  var fields = ['typeName', 'alarmCode', 'codeDescribe', 'isShow'];

  var self = this;
  var fn = {
    initData: function (warn) {
      if (SysUtil.isEmpty(warn)) {
        warn = {
          isShow: 1
        };
      }
      self.setDataFromObj(warn, fields, '');
    }
  };

  this.checkValid = function () {
    var fields = ['typeName', 'alarmCode', 'codeDescribe'];
    for (var i = 0; i < fields.length; i++) {
      var field = fields[i];
      var value = this[field];
      if (value === '') {
        return field;
      }
    }

    var alarmCode = this.alarmCode;
    var code = parseInt(alarmCode);
    if (isNaN(code)) {
      return 'codeNotValid';
    }

    if (code <= 0 || String(code) !== alarmCode) {
      return 'codeNotValid';
    }

    return '';
  };

  this.getObject = function () {
    var postData = {};
    this.setPostData(postData, fields);
    var alarmCode = parseInt(this.alarmCode);
    postData.alarmCode = alarmCode;
    return postData;
  };

  fn.initData(warn);
};
